/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} x
 * @return {ListNode}
 */

 let {list,ListNode}=require('./lianbiao');

 var partition = function(head, x) {
    if(!head || !head.next){
        return head;
    }
    let newhead=new ListNode(0,head);
    let node=newhead;
    while(node.next && node.next.val<x){
        node=node.next;
    }
    let p=node;
    while(node && node.next){
        if(node.next.val<x){
            let n=node.next;
            node.next=n.next;
            n.next=p.next;
            p.next=n;
            p=n;
        }
        else{
            node=node.next;
        }
        
    }
    return newhead.next;
};

let arr=[1,4,3,0,2,5,2];
let head=list(arr);
console.log(partition(head,3));